/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package simulateurs.view.controllersView;

import java.awt.*;
import java.util.ArrayList;
import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import simulateurs.model.monde.Equipe;
import simulateurs.view.I_View;
import simulateurs.view.View;

/**
 *
 * @author Lunesco
 */
public class ControllersPanelView extends WoodPanel implements I_View {
	private View parentView=null;
	private ArrayList<JPanel> scorePanels=null;
	private ArrayList<JLabel> nomEquipes=null;
	private ArrayList<JLabel> scores=null;
	private ArrayList<Equipe> listeEquipes=null;	
	
	public ControllersPanelView(View parentView){
		this.parentView=parentView;
		this.listeEquipes=this.parentView.getModel().getArene().getListeEquipes();
		initControllersPanel();
	}
	
	private void initControllersPanel(){
		this.setBackground(new Color(0xDDDDDD));
		this.setLayout(new BorderLayout());
		
		this.scorePanels=new ArrayList<>();
		this.nomEquipes=new ArrayList<>();
		this.scores=new ArrayList<>();
		JLabel lab=new JLabel("     Score  Board     ");
		lab.setForeground(new Color(0x8B4513).darker().darker());
		lab.setBackground(new Color(0, true));
		this.add(lab, BorderLayout.NORTH);
		
		int n=this.listeEquipes.size();
		WoodPanel scoreBoard=new WoodPanel();
		scoreBoard.setLayout(new GridLayout(0,1));
		for(int i=0; i<n; i++){
			Equipe e=this.listeEquipes.get(i);
			String str=e.getNom();
			if(str=="" || str==null)str="Null";
			if(str.length()>6)str=str.substring(0, 5);
			JLabel nom=new JLabel(str);
			JLabel score=new JLabel(new Integer(e.getScore()).toString());
			int nEquipes=this.listeEquipes.size();
			int sizeNom;
			int sizeScore;
			if(nEquipes>4) {
				sizeNom=(int)(this.parentView.getModel().getArene().getHauteur()/(this.listeEquipes.size()*6));
				sizeScore=(int)(this.parentView.getModel().getArene().getHauteur()/(this.listeEquipes.size()*3));				
			}
			else {
				sizeNom=20;
				sizeScore=50;
			}
			nom.setMaximumSize(new Dimension(100, 100));
			nom.setFont(new Font("Tahoma", Font.BOLD, sizeNom));
			nom.setForeground(e.getCouleur());
			nom.setVerticalAlignment(SwingConstants.BOTTOM);
			nom.setHorizontalAlignment(SwingConstants.CENTER);
			score.setFont(new Font("Tahoma", Font.BOLD, sizeScore));
			score.setForeground(new Color(0x8B4513).darker().darker());
			score.setVerticalAlignment(SwingConstants.TOP);
			score.setHorizontalAlignment(SwingConstants.CENTER);
			this.nomEquipes.add(nom);
			this.scores.add(score);
			
			JPanel jp=new JPanel();
			jp.setLayout(new GridLayout(2,1));
			jp.setMaximumSize(new Dimension(100, 600));
			jp.setBackground(new Color(0, true));
			jp.add(nom);
			jp.add(score);
			this.scorePanels.add(jp);
			scoreBoard.add(jp);
		}
		scoreBoard.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
		this.add(scoreBoard, BorderLayout.CENTER);
	}
	
	@Override
	public void repeindre() {
		for(int i=0; i<scores.size(); i++){
			scores.get(i).setText(new Integer(this.listeEquipes.get(i).getScore()).toString());
		}
		this.repaint();
	}	
}
